package com.example.librarymanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.librarymanagement.dao.ReaderMapper;
import com.example.librarymanagement.dto.reader.ReaderListDto;
import com.example.librarymanagement.entity.Reader;
import com.example.librarymanagement.service.IReaderService;
import com.example.librarymanagement.vo.ReaderVo;
import org.springframework.stereotype.Service;

/**
 * @author ZHB
 */

@Service
public class ReaderServiceImpl extends ServiceImpl<ReaderMapper, Reader> implements IReaderService {

    @Override
    public IPage<ReaderVo> getReaderList(ReaderListDto readerListDto) {
        IPage<ReaderVo> page = new Page<>(readerListDto.getCurrent(), readerListDto.getSize());
        return baseMapper.getReaderList(page, readerListDto);
    }

    @Override
    public Reader addReader(Reader reader) {
        int result = baseMapper.insert(reader);
        if (result > 0) {
            return getOne(new QueryWrapper<Reader>().eq("id_card", reader.getIdCard()));
        }
        return null;
    }
}
